Using multiple keys for git

Problem

Sometimes you'll have multiple github, gitlab, azure accounts and you'll have multiple ssh keys for each of those

Solution

Use ssh keys and define aliases in ssh config

How?

  • Generate ssh keypairs and add to each of your account
  • Edit/Create ssh config file ($HOME/.ssh/config)

    Host github.com
         HostName github.com
         IdentityFile ~/.ssh/rsa_github
         IdentitiesOnly Yes
    Host gitlab.com
         HostName gitlab.com
         IdentityFile ~/.ssh/rsa_gitlab
         IdentitiesOnly Yes
    Host azure.com
         HostName azure.com
         IdentityFile ~/.ssh/rsa_azure
         IdentitiesOnly Yes
    
  • Test the connection

    ssh -T git@github.com
    ssh -T git@gitlab.com
    ssh -T git@azure.com
    
Copyright 2020-2021 nerding_it ( HTML).
Last updated 2021-08-11 Wed 12:27.
Built with Emacs 27.2 (Org mode 9.4.4).
Subscribe to Weekly News Letter
We'll never share your email with anyone else.